Skip to main content

ALC5640

This document primarily introduces the development and adaptation process for audio, using the ALC5640 as an example. The Realtek ALC5640 is a low-power, high-performance audio codec widely used in various embedded systems. This guide aims to help users successfully adapt and use the ALC5640 audio codec on the Jetson Orin Nano platform.

Audio Architecture Overview

Common Terms

ModuleComponent
I2SI2S interface for transmitting digital audio data, used to connect external audio devices
DSPKDigital speaker interface for connecting and controlling digital speakers
DMICDigital microphone controller for managing and processing digital microphone input
MixerMixer for combining multiple audio signals into one output signal
AMXAudio multiplexer for multiplexing multiple audio signals into one output channel
ADXAudio demultiplexer for separating one audio signal into multiple channels
SFCSample rate converter for converting audio signals to different sample rates
MVCMaster volume controller for adjusting the master volume of audio signals
ADMAAudio direct memory access for efficient audio data transmission, supporting 32 channels
ADMAIFAHUB DMA interface for data transfer between audio hardware units and memory, supporting 20 TX/RX channels, designed for Jetson, supporting multi-channel audio data transfer
XBARCrossbar (audio routing) for dynamically routing audio data between multiple audio sources and destinations, the core module for audio data routing, supporting dynamic audio path configuration
APEIndependent hardware module in NVIDIA Jetson devices dedicated to audio processing, featuring low power consumption and high performance
AHUBCore component of APE responsible for audio data routing and processing, containing multiple NVIDIA-specific hardware modules

Audio SW 架构

On the NVIDIA Jetson platform, the driver adaptation for the ALC5640 audio codec is primarily based on the ALSA ASoC (Audio System on Chip) framework. ASoC is the standard audio subsystem of the Linux kernel for managing embedded audio hardware, including codecs, platform DMA, and digital audio interfaces (DAI). The ASoC driver architecture mainly consists of three core components:

  1. Codec Driver - Manages the ALC5640 register configuration and audio paths.
  2. Platform Driver - Handles Tegra DMA and I2S interfaces.
  3. Machine Driver - Binds hardware and defines audio routing.

There are some NVIDIA-specific features, such as:

  1. Audio Processing Engine (APE), a dedicated hardware module for independent audio tasks.

  2. Audio Hub (AHUB), which includes the following two core components:

    XBAR: The core of dynamic audio routing, supporting real-time path switching, equivalent to a switch.

    ADMAIF: A dedicated 32-channel DMA engine.

ALC5640 Driver Adaptation Process

Prerequisites

  • Confirm the I2C address of the ALC5640 codec chip.

  • Obtain the ALC5640 mode (master/slave mode) and clock information (e.g., MCLK/BCLK/LRCK) from the datasheet.

Device Tree Configuration

In the device tree file Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/nv-platform/tegra234-NG45XX-p3768-0000+p3767-0000-common.dts, complete the following configurations:

  • I2C node configuration: Add codec chip configuration as shown below:

    i2c@3160000 {
    status = "okay";

    rt5640: audio-codec@1c {
    status = "okay";
    compatible = "realtek,rt5640";
    reg = <0x1c>;
    interrupt-parent = <&gpio>;
    interrupts = <TEGRA234_MAIN_GPIO(P, 6) 0>;
    clocks = <&bpmp TEGRA234_CLK_AUD_MCLK>;
    clock-names = "mclk";

    realtek,dmic1-data-pin = <RT5640_DMIC1_DATA_PIN_NONE>;
    realtek,dmic2-data-pin = <RT5640_DMIC2_DATA_PIN_NONE>;
    realtek,jack-detect-source = <RT5640_JD_SRC_HDA_HEADER>;

    sound-name-prefix = "CVB-RT";
    sel_jd_source = <3>;

    port {
    rt5640_ep: endpoint {
    remote-endpoint = <&i2s4_dap>;
    mclk-fs = <256>;
    };
    };
    };
    };
  • I2S node configuration: Enable ahub, I2S controller, and connect to the rt5640_ep codec chip as shown below:

    aconnect@2900000 {
    status = "okay";
    ahub@2900800 {
    status = "okay";
    i2s@2901300 {
    status = "okay";
    ports {
    port@1 {
    endpoint {
    dai-format = "i2s";
    remote-endpoint = <&rt5640_ep>;
    };
    };
    };
    };
    };
    };
  • Sound card node definition and routing configuration as shown below:

    sound {
    status = "okay";
    compatible = "nvidia,tegra186-audio-graph-card",
    "nvidia,tegra186-ape";
    nvidia-audio-card,mclk-fs = <256>;
    label = "NVIDIA Jetson Orin Nano APE";

    nvidia-audio-card,widgets =
    "Headphone", "CVB-RT Headphone Jack",
    "Microphone", "CVB-RT Mic Jack",
    "Speaker", "CVB-RT Int Spk",
    "Microphone", "CVB-RT Int Mic";

    nvidia-audio-card,routing =
    "CVB-RT Headphone Jack", "CVB-RT HPOL",
    "CVB-RT Headphone Jack", "CVB-RT HPOR",
    "CVB-RT Headphone Jack", "CVB-RT LOUTL",
    "CVB-RT Headphone Jack", "CVB-RT LOUTR",
    "CVB-RT IN1P", "CVB-RT Mic Jack",
    "CVB-RT IN2P", "CVB-RT Mic Jack",
    "CVB-RT IN3P", "CVB-RT Mic Jack",
    "CVB-RT Int Spk", "CVB-RT SPOLP",
    "CVB-RT Int Spk", "CVB-RT SPORP",
    "CVB-RT DMIC1", "CVB-RT Int Mic",
    "CVB-RT DMIC2", "CVB-RT Int Mic";
    };
  • DAI link configuration, linking the CPU ADMA intermediate xbar to the codec alc5640.

    nvidia-audio-card,dai-link@79 {
    link-name = "rt5640-playback";

    codec {
    sound-dai = <&rt5640 0>;
    prefix = "CVB-RT";
    };
    };

Kernel Configuration

In Linux_for_Tegra/source/kernel/kernel-jammy-src/arch/arm64/configs/defconfig, add the following configuration:

CONFIG_SND_SOC_ALC5640=m

System Adaptation

  • Start the device and copy the compiled dtb and snd-soc-rt5640.ko to the AIBOX using scp.
cd Linux_for_Tegra/source

scp ./kernel-devicetree/generic-dts/dtbs/tegra234-NG45XX-p3768-0000+p3767-0003-nv-super.dtb milesight@192.168.60.3:/home/milesight
scp ./kernel/kernel-jammy-src/sound/soc/codecs/snd-soc-rt5640.ko milesight@192.168.60.3:/home/milesight
  • Copy snd-soc-rt5640.ko to the modules directory and execute depmod to load the driver.
sudo cp ./snd-soc-rt5640.ko /lib/modules/5.15.148-tegra/kernel/sound/soc/codecs/snd-soc-rt5640.ko

sudo depmod
  • After completion, restart the development board.

Testing and Verification

  • Headphone Speaker
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"

amixer -c APE cset name="CVB-RT DAC MIXL INF1 Switch" "on"
amixer -c APE cset name="CVB-RT DAC MIXR INF1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo DAC MIXL DAC L1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo DAC MIXR DAC R1 Switch" "on"

amixer -c APE cset name="CVB-RT HPO MIX DAC1 Switch" "on"
amixer -c APE cset name="CVB-RT HP L Playback Switch" "on"
amixer -c APE cset name="CVB-RT HP R Playback Switch" "on"
amixer -c APE cset name="CVB-RT HP Playback Volume" "31,31"
amixer -c APE cset name="CVB-RT DAC1 Playback Volume" "175,175"

# Test
aplay xx.wav
  • Headphone Microphone
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"
amixer -c APE cset name="CVB-RT IN1 Boost" 8
amixer -c APE cset name="CVB-RT RECMIXL BST1 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo ADC1 Mux" "ADC"
amixer -c APE cset name="CVB-RT Stereo ADC MIXL ADC1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo ADC MIXR ADC1 Switch" "on"
amixer -c APE cset name='CVB-RT ADC Capture Switch' on

# Test, record and play
arecord -Dhw:APE,1 -c 2 -r 44100 -f S16_LE -d 5 xxx.wav
aplay xxx.wav
  • External Speaker
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"

amixer -c APE cset name="CVB-RT Speaker Channel Switch" on
amixer -c APE cset name="CVB-RT Speaker L Playback Switch" on
amixer -c APE cset name="CVB-RT Speaker R Playback Switch" on

amixer -c APE cset name="CVB-RT Speaker Playback Volume" 50%
amixer -c APE cset name="CVB-RT DAC1 Playback Volume" "175,175"

amixer -c APE cset name="CVB-RT DAC MIXL INF1 Switch" on
amixer -c APE cset name="CVB-RT DAC MIXR INF1 Switch" on
amixer -c APE cset name="CVB-RT SPK MIXL DAC L1 Switch" on
amixer -c APE cset name="CVB-RT SPK MIXR DAC R1 Switch" on

amixer -c APE cset name="CVB-RT SPOL MIX SPKVOL L Switch" on
amixer -c APE cset name="CVB-RT SPOR MIX SPKVOL R Switch" on
amixer -c APE cset name="CVB-RT OUT MIXL SPK MIXL Switch" on
amixer -c APE cset name="CVB-RT OUT MIXR SPK MIXR Switch" on

# Test
aplay aaa.wav
  • External Microphone
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"

amixer -c APE cset name="CVB-RT IN2 Boost" 8
amixer -c APE cset name="CVB-RT IN3 Boost" 8
amixer -c APE cset name="CVB-RT RECMIXL BST2 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST2 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXL BST3 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST3 Switch" "on"
amixer -c APE cset name='CVB-RT ADC Capture Switch' on

# Test, record and play
arecord -Dhw:APE,1 -c 2 -r 44100 -f S16_LE -d 5 aaa.wav
aplay aaa.wav

Troubleshooting

  • No sound output

    • Confirm MCLK/BCLK are normal.

    • Confirm I2S.

    • Check amixer routing configuration.

  • High noise in recording

    • Check the sample rate.

References

Audio Setup and Development — NVIDIA Jetson Linux Developer Guide